package actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import model.StudentDBModel;
import data.StudentData;

import java.util.Vector;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class NameAction extends Action {

	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	{
		
		RowSet crsCountries = StudentDBModel.getAllCountries();
		
		// Store the RowSet in the request scope
		request.setAttribute("crsCountries", crsCountries);
		StudentData studentData = (StudentData) request.getSession().getAttribute("studentData");
		if(studentData == null)
		{
			System.err.println("NEW SESSION STUDENT DATA");
			studentData = new StudentData();
			studentData.setFirstName(request.getParameter("firstName"));
			studentData.setMiddleInitial(request.getParameter("middleInitial"));
			studentData.setLastName(request.getParameter("lastName"));
			
			
		}
		if(mapping.getPath().equals("/pages/students/Residency"))
		{
			studentData.setCitizen(request.getParameter("citizen"));
			studentData.setCitizenID(request.getParameter("citizenID"));
		}
		if(mapping.getPath().equals("/pages/students/Address"))
		{
			studentData.setResident(request.getParameter("resident"));
			studentData.setResidentID(request.getParameter("residentID"));
			
		}

		
		request.getSession().setAttribute("studentData", studentData);
		
		Vector<String> formData = studentData.getFormData();
		request.getSession().setAttribute("formData", formData);

		return mapping.findForward("success");
	}
}
